package com.example.treehole.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {


    /**
    * date: 2022/4/20 0:51
    * @author: zzs
    * Description: 根据long时间参数返回对应的时间提示
    */
    public static String timeTip(long createTime){
        long curTime=System.currentTimeMillis();
        long t=curTime-createTime;
        t=t/1000;  //获取秒数
        if (t>3600){    //如果超过一小时
            t=t/3600;
            if (t>365*24)  //如果超过一年
                return new SimpleDateFormat("yyyy-MM-dd").format(createTime);
            else if (t>24)   //超过一天
                return new SimpleDateFormat("MM-dd").format(createTime);
            else
                return t+"小时前";
        }else if (t>60){    //超过一分钟
            t=t/60;
            return t+"分钟前";
        }else{              //一分钟内
            return t+"秒前";
        }
    }

    /**
    * date: 2022/4/20 0:53
    * @author: zzs
    * Description: 返回当前日期指定的前几天的月日
    */
    public static String getPastDate(int past) {
         Calendar calendar = Calendar.getInstance();
         calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
         Date today = calendar.getTime();
         SimpleDateFormat format = new SimpleDateFormat("MM/dd");
         String result = format.format(today);
         return result;
     }

}
